﻿using System;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.DependencyInjection.Extensions;
using WxLib.Business;
using WxLib.Pay;
using WxLib.QRCode;
using WxLib.Sns;
using WxLib.TemplateMessage;
using WxLib.CustomerService;

namespace WxLib
{
    public static class WxServiceCollectionExtensions
    {
        public static IServiceCollection AddWxApiService(this IServiceCollection services)
        {
            if (services == null)
            {
                throw new ArgumentNullException(nameof(services));
            }

            services.AddOptions();
            services.TryAdd(ServiceDescriptor.Singleton<PayToBank, PayToBank>());
            services.TryAdd(ServiceDescriptor.Singleton<PayToUser, PayToUser>());
            services.TryAdd(ServiceDescriptor.Singleton<WxAppPay, WxAppPay>());
            services.TryAdd(ServiceDescriptor.Singleton<WxAppQRCode, WxAppQRCode>());
            services.TryAdd(ServiceDescriptor.Singleton<WxSns, WxSns>());
            services.TryAdd(ServiceDescriptor.Singleton<WxTemplateMessageApi, WxTemplateMessageApi>());
            services.TryAdd(ServiceDescriptor.Singleton<WxCustomerMessageService, WxCustomerMessageService>());
            return services;
        }


        public static IServiceCollection AddWxApiService(this IServiceCollection services, Action<WxApiOptions> setupAction)
        {
            if (services == null)
            {
                throw new ArgumentNullException(nameof(services));
            }

            if (setupAction == null)
            {
                throw new ArgumentNullException(nameof(setupAction));
            }

            services.AddWxApiService();
            services.Configure(setupAction);

            return services;
        }
    }
}
